import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { CacheService } from '@services/cache.service';
import { InstallService } from '@services/data.service/index';

@Component({
  selector: 'install-step',
  templateUrl: './install-step.html',
  styleUrls: ['install-step.scss']
})
export class InstallComponent implements OnInit {
  @Input() roomInfo;
  @Input() installData;
  @Input() Step;
  click = false; // 防止重复点击
  CodeInfo;
  Style;
  Install = {
    case: ''
  };

  @Output() NextNum: EventEmitter<any> = new EventEmitter();
  constructor(public modalCtrl: ModalController, public cache: CacheService,
    private installService: InstallService) {
  }

  // 初始页面显示
  ngOnInit() {
    console.log('安装页面房间信息', this.roomInfo);
    this.Style = {
      title: '安装位置',
      dataValueList: [{ id: 1, name: '天花板', mark: true }, { id: 2, name: '墙壁', mark: true }, { id: 3, name: '地面', mark: true }, { id: 4, name: '柜内', mark: true }],
      defaultOps: this.installData.mapping || ''
    };
    this.Step.state = 1;
    setTimeout(() => {
      this.click = true;
    }, 1500);
  }

  // 切换步骤
  toNext(i) {
    this.click = false;
    if (this.roomInfo.Type === 0) {
      this.installData.data2 = this.CodeInfo || '';
    } else {
      this.installData.mapping = this.Install.case;
      this.installData.data2 = this.Install.case;
    }
    this.Step.now = i;
    this.installData.step = 2;
    this.installService.saveInstallData(this.installData.areaId, this.installData.meterId, this.installData);
    this.NextNum.emit(this.Step.now);
    setTimeout(() => {
      this.click = true;
    }, 1000);
  }

  selectedObj(e) {
    if (e) {
      this.CodeInfo = e.name;
      this.installData.mapping = e.name;
    }
  }
}
